package com.simon.hse.activity.safe.jsa;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.simon.hse.R;
import com.simon.hse.activity.BaseActivity;
import com.simon.hse.adapter.CommonEmptyAdapter;
import com.simon.hse.adapter.CommonViewHolder;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

/**
 * 安全技术措施查询列表
 */
@SuppressWarnings("all")
@ContentView(R.layout.activity_risk_recognition_safe_step_query_list)
public class RiskRecognitionAndSafeStepQuertListActivity extends BaseActivity {
    @ViewInject(R.id.tv_common_title)
    TextView mTv_common_title;

    @ViewInject(R.id.iv_common_right)
    ImageView mIv_common_right;

    @ViewInject(R.id.iv_common_right2)
    ImageView mIv_common_right2;

    @ViewInject(R.id.recyclerview)
    RecyclerView mRecyclerView;

    CommonEmptyAdapter mCommonEmptyAdapter;

    private List<String> mDataBeanList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mTv_common_title.setText("风险识别及安全措施");
        mIv_common_right.setImageResource(R.mipmap.icon_delete);
        mIv_common_right2.setVisibility(View.VISIBLE);
        mIv_common_right2.setImageResource(R.mipmap.tab_add_icon);
        initRecyclerView();
        initData();
    }

    @Event(value = {R.id.iv_common_left,R.id.iv_common_right2})
    private void finish(View view) {
        switch (view.getId()) {
            case R.id.iv_common_left:
                finish();
                break;
            case R.id.iv_common_right2:
                Intent intent = new Intent(RiskRecognitionAndSafeStepQuertListActivity.this, RiskRecognitionAndSafeStepQuertActivity.class);
                startActivity(intent);
                break;
        }
    }

    private void initRecyclerView() {
        LinearLayoutManager llm = new LinearLayoutManager(RiskRecognitionAndSafeStepQuertListActivity.this);
        mRecyclerView.setLayoutManager(llm);
        // 如果Item够简单，高度是确定的，打开FixSize将提高性能
        mRecyclerView.setHasFixedSize(true);
        // 设置Item默认动画，加也行，不加也行
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
        mRecyclerView.setNestedScrollingEnabled(false);
        mCommonEmptyAdapter = new CommonEmptyAdapter(RiskRecognitionAndSafeStepQuertListActivity.this, R.layout.layout_item_riskrecognition_safestep, mDataBeanList);
        mCommonEmptyAdapter.setItemDatasListener(new CommonEmptyAdapter.ItemDatasListener<String>() {
            @Override
            public void setItemDatas(CommonViewHolder holder, String dataBean, int position) {
            }
        });

        mCommonEmptyAdapter.setOnItemClickListener(new CommonEmptyAdapter.OnItemClickListener() {
            @Override
            public void setOnItemClickListener(View view, int position) {
//                Intent intent = new Intent(RiskRecognitionAndSafeStepQuertListActivity.this, RiskRecognitionAndSafeStepQuertActivity.class);
//                startActivity(intent);
            }

            @Override
            public void setOnItemLongClickListener(View view, int position) {

            }
        });

        mRecyclerView.setAdapter(mCommonEmptyAdapter);
    }

    private void initData() {
        for (int i = 1; i < 5; i++) {
            mDataBeanList.add(i + "");
        }
        mCommonEmptyAdapter.notifyDataSetChanged();
    }
}
